<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <style>
        .error{
            color: red;
        }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/style.css"/>
    <link href="assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/ace.min.css" />
    <link rel="stylesheet" href="font/css/font-awesome.min.css" />
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
    <![endif]-->
    <script th:src="@{/js/jquery-1.7.2.min.js}"></script>
    <script th:src="@{/js/jquery.metadata.js}"></script>
    <script th:src="@{/js/jquery.validate.js}"></script>
    <script th:src="@{/js/jquery.validate.messages_cn.js}"></script>
    <!--<script src="js/jquery-1.9.1.min.js"></script>-->
    <script src="assets/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="Widget/Validform/5.3.2/Validform.min.js"></script>
    <script src="assets/js/typeahead-bs2.min.js"></script>
    <script src="assets/js/jquery.dataTables.min.js"></script>
    <script src="assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="assets/layer/layer.js" type="text/javascript" ></script>
    <script src="js/lrtk.js" type="text/javascript" ></script>
    <script src="assets/layer/layer.js" type="text/javascript"></script>
    <script src="assets/laydate/laydate.js" type="text/javascript"></script>
    <script type="text/javascript">
        /*拿到角色分类菜单*/
        $(function () {
            $.ajax({
                url:'/role/showRole',
                type: 'get',
                dataType:'json',
                success:function (data) {
                    $('#show').html('');
                    $('.select').html('');/*添加管理员---下拉框设置角色*/
                    $.each(data,function (i,item) {
                        $('#show').append('<li><i class="fa fa-users orange"></i> <a href="javascript:void(0)" onclick="change('+item.rid+')">'+item.name+'</a></li>');
                        $('.select').append('<option value="'+item.rid+'">'+item.name+'</option>');
                    })
                }
            })
        })

        /*点击不同角色后，跳转到不同角色的管理员列表*/
        function change(id) {
            $.ajax({
                url:'/changeRole',
                type: 'get',
                dataType:'json',
                data:'id='+id,
                success:function (data) {
                    $('#content').html('');
                    $.each(data,function (i,item) {
                        if (item.state==0){
                            $('#content').append('<tr>' +
                                '<td><label><input type="checkbox" name="flag" value="'+item.id+'" class="ace"><span class="lbl"></span></label></td>' +
                                '<td>'+item.id+'</td>' +
                                '<td>'+item.loginName+'</td>' +
                                '<td>'+item.gender+'</td>' +
                                '<td>'+item.phone+'</td>' +
                                '<td>'+item.role.name+'</td>' +
                                '<td class="td-status"><span class="label label-success radius">已启用</span></td>' +
                                '<td class="td-manage">' +
                                '<a onClick="member_stop(this,'+item.id+')"  href="javascript:;" title="停用"  class="btn btn-xs btn-success"><i class="fa fa-check  bigger-120"></i></a>' +
                                '<a title="编辑" onclick="administrator_update('+item.id+')" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a>' +
                                '<a title="删除" href="javascript:;"  onclick="member_del(this,'+item.id+')" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>' +
                                '</td>' +
                                '</tr>');
                        }else {
                            $('#content').append('<tr>' +
                                '<td><label><input type="checkbox" name="flag" value="'+item.id+'" class="ace"><span class="lbl"></span></label></td>' +
                                '<td>'+item.id+'</td>' +
                                '<td>'+item.loginName+'</td>' +
                                '<td>'+item.gender+'</td>' +
                                '<td>'+item.phone+'</td>' +
                                '<td>'+item.role.name+'</td>' +
                                '<td class="td-status"><span class="label label-defaunt radius">已禁用</span></td>' +
                                '<td class="td-manage">' +
                                '<a onClick="member_start(this,'+item.id+')"  href="javascript:;" title="启用"  class="btn btn-xs"><i class="fa fa-close bigger-120"></i></i></a>' +
                                '<a title="编辑" onclick="administrator_update('+item.id+')" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a>' +
                                '<a title="删除" href="javascript:;"  onclick="member_del(this,'+item.id+')" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>' +
                                '</td>' +
                                '</tr>');
                        }

                    })
                }
            })
        }

        /*点击到其它角色列表后，再点击全部管理员后可遍历全部管理员*/
        function jump(){
            $.ajax({
                url:'/showAll1',
                type: 'get',
                dataType:'json',
                success:function (data) {
                    $('#content').html('');
                    $.each(data,function (i,item) {
                        if (item.state==0){
                            $('#content').append('<tr>' +
                                '<td><label><input type="checkbox" name="flag" value="'+item.id+'" class="ace"><span class="lbl"></span></label></td>' +
                                '<td>'+item.id+'</td>' +
                                '<td>'+item.loginName+'</td>' +
                                '<td>'+item.gender+'</td>' +
                                '<td>'+item.phone+'</td>' +
                                '<td>'+item.role.name+'</td>' +
                                '<td class="td-status"><span class="label label-success radius">已启用</span></td>' +
                                '<td class="td-manage">' +
                                '<a onClick="member_stop(this,'+item.id+')"  href="javascript:;" title="停用"  class="btn btn-xs btn-success"><i class="fa fa-check  bigger-120"></i></a>' +
                                '<a title="编辑" onclick="administrator_update('+item.id+')" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a>' +
                                '<a title="删除" href="javascript:;"  onclick="member_del(this,'+item.id+')" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>' +
                                '</td>' +
                                '</tr>');
                        }else {
                            $('#content').append('<tr>' +
                                '<td><label><input type="checkbox" name="flag" value="'+item.id+'" class="ace"><span class="lbl"></span></label></td>' +
                                '<td>'+item.id+'</td>' +
                                '<td>'+item.loginName+'</td>' +
                                '<td>'+item.gender+'</td>' +
                                '<td>'+item.phone+'</td>' +
                                '<td>'+item.role.name+'</td>' +
                                '<td class="td-status"><span class="label label-defaunt radius">已禁用</span></td>' +
                                '<td class="td-manage">' +
                                '<a onClick="member_start(this,'+item.id+')"  href="javascript:;" title="启用"  class="btn btn-xs"><i class="fa fa-close bigger-120"></i></a>' +
                                '<a title="编辑" onclick="administrator_update('+item.id+')" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a>' +
                                '<a title="删除" href="javascript:;"  onclick="member_del(this,'+item.id+')" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>' +
                                '</td>' +
                                '</tr>');
                        }
                    })
                }
            })
        }

        /*批量删除管理员*/
        function deleteadmin(){
            var obj = document.getElementsByName("flag");/*拿到所有name=flag的对象*/
            var result = $("input[type='checkbox']").is(':checked');
            if (result==false) {
                return alert('请点击复选框在进行操作');
            }
            var s= "";
            for (var i = 0; i < obj.length; i++) {
                if (obj[i].checked) {
                    s +=obj[i].value+",";
                }
            };
            $.ajax({
                url:'/delSome',
                type:'get',
                dataType:'json',
                data:'ids='+s,
                success:function (data) {
                    if (data>=1){
                        window.location.reload();
                    }
                }
            })
        }
    </script>
    <title>管理员</title>
</head>

<body>
<div class="page-content clearfix">
    <div class="administrator">
        <div class="d_Confirm_Order_style">

            <!--操作-->
            <div class="border clearfix">
       <span class="l_f">
        <a href="javascript:void(0)" id="administrator_add" onclick="administrator_add()" class="btn btn-warning"><i class="fa fa-plus"></i> 添加管理员</a>
        <a href="javascript:void(0)" onclick="deleteadmin()" class="btn btn-danger"><i class="fa fa-trash"></i> 批量删除</a>
       </span>
                <span class="r_f">共：<b th:text="${count}"></b>人</span>
            </div>
            <!--管理员列表-->
            <div class="clearfix administrator_style" id="administrator">
                <div class="left_style">
                    <div id="scrollsidebar" class="left_Treeview">
                        <div class="show_btn" id="rightArrow"><span></span></div>
                        <div class="widget-box side_content" >
                            <div class="side_title"><a title="隐藏" class="close_btn"><span></span></a></div>
                            <div class="side_list"><div class="widget-header header-color-green2"><h4 class="lighter smaller">管理员分类列表</h4></div>
                                <div class="widget-body">
                                    <ul class="b_P_Sort_list">
                                        <li><i class="fa fa-users green"></i> <a href="javascript:void(0)" onclick="jump()">全部管理员</a></li>
                                        <div id="show">
                                        <li><i class="fa fa-users orange"></i> <a href="#"></a></li>
                                        </div>
                                        <!--<li><i class="fa fa-users orange"></i> <a href="#">普通管理员（5）</a></li>
                                        <li><i class="fa fa-users orange"></i> <a href="#">产品编辑管理员（4）</a></li>
                                        <li><i class="fa fa-users orange"></i> <a href="#">管理员（1）</a></li>-->
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="table_menu_list"  id="testIframe">
                    <table class="table table-striped table-bordered table-hover" id="sample_table">
                        <thead>
                        <tr>
                            <th width="25px"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
                            <th width="80px">编号</th>
                            <th width="250px">登录名</th>
                            <th width="100px">性别</th>
                            <th width="100px">电话</th>
                            <th width="100px">角色</th>
                            <!--<th width="180px">加入时间</th>-->
                            <th width="70px">状态</th>
                            <th width="200px">操作</th>
                        </tr>
                        </thead>
                        <tbody id="content">
                        <tr th:each="admin:${alladmin}">
                            <td><label><input type="checkbox" th:value="${admin.id}" name="flag" class="ace"><span class="lbl"></span></label></td>
                            <td th:text="${admin.id}"></td>
                            <td th:text="${admin.loginName}"></td>
                            <td th:text="${admin.gender}"></td>
                            <td th:text="${admin.phone}"></td>
                            <td th:text="${admin.role.name}"></td>
                            <!--<td>2016-6-29 12:34</td>-->
                            <td th:if="${admin.state eq 0}" class="td-status"><span class="label label-success radius">已启用</span></td>
                            <td th:if="${admin.state eq 1}" class="td-status"><span class="label label-defaunt radius">已禁用</span></td>
                            <td class="td-manage">
                                <span th:if="${admin.state eq 0}"><a th:onClick="'member_stop(this,'+${admin.id}+')'"  href="javascript:;" title="停用"  class="btn btn-xs btn-success"><i class="fa fa-check  bigger-120"></i></a></span>
                                <span th:if="${admin.state eq 1}"><a th:onClick="'member_start(this,'+${admin.id}+')'"  href="javascript:;" title="启用"  class="btn btn-xs"><i class="fa fa-close bigger-120"></i></a></span>
                                <a title="编辑" th:onclick="'administrator_update('+${admin.id}+');'" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a>
                                <a title="删除" href="javascript:;"  th:onclick="member_del(this,[[${admin.id}]])" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>
                            </td>
                        </tr>
                        <!--<tr>
                            <td><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>
                            <td>2</td>
                            <td>admin12345</td>
                            <td>18934334544</td>
                            <td>2345454@qq.com</td>
                            <td>管理员</td>
                            <td>2016-6-29 12:34</td>
                            <td class="td-status"><span class="label label-success radius">已启用</span></td>
                            <td class="td-manage">
                                <a onClick="member_stop(this,'10001')"  href="javascript:;" title="停用"  class="btn btn-xs btn-success"><i class="fa fa-check  bigger-120"></i></a>
                                <a title="编辑" onclick="member_edit('编辑','member-add.html','4','','510')" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a>
                                <a title="删除" href="javascript:;"  onclick="member_del(this,'1')" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>
                            </td>
                        </tr>-->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!--添加管理员-->
    <div id="add_administrator_style" class="add_menber" style="display:none">
        <form th:action="@{/addAdmin}" method="post" id="form-admin-add">
            <div class="form-group">
                <label class="form-label"><span class="c-red">*</span> 管理员登录名：</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" placeholder="" id="user-name" name="loginName" datatype="*2-16" nullmsg="登录名不能为空">
                    <label class="error"></label>
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label"><span class="c-red">*</span>管理员真实名：</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" placeholder="" id="user-name1" name="name" datatype="*2-16" nullmsg="真实名不能为空">
                    <label class="error"></label>
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label"><span class="c-red">*</span>初始密码：</label>
                <div class="formControls">
                    <input type="password" placeholder="密码" name="password" autocomplete="off" value="" class="input-text" datatype="*6-20" nullmsg="密码不能为空">
                    <label class="error"></label>
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label "><span class="c-red">*</span>确认密码：</label>
                <div class="formControls ">
                    <input type="password" placeholder="确认新密码" autocomplete="off" class="input-text Validform_error" errormsg="您两次输入的新密码不一致！" datatype="*" nullmsg="请再输入一次新密码！" recheck="userpassword" id="newpassword2" name="pwd">
                    <label class="error"></label>
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label "><span class="c-red">*</span>性别：</label>
                <div class="formControls  skin-minimal">
                    <label><input name="gender" type="radio" value="男" class="ace"><span class="lbl">男</span></label>&nbsp;&nbsp;
                    <label><input name="gender" type="radio" value="女" class="ace"><span class="lbl">女</span></label>
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label "><span class="c-red">*</span>手机：</label>
                <div class="formControls ">
                    <input type="text" class="input-text" value="" placeholder="" id="user-tel" name="phone" datatype="m" nullmsg="手机号不能为空">
                    <label class="error"></label>
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>

            <div class="form-group">
                <label class="form-label">角色：</label>
                <div class="formControls "> <span class="select-box" style="width:150px;">
				<select class="select" name="role.rid" size="1">
					<option value="0">超级管理员</option>
					<option value="1">管理员</option>
					<option value="2">栏目主辑</option>
					<option value="3">栏目编辑</option>
				</select>
				</span> </div>
            </div>

            <div>
                <input class="btn btn-primary radius" type="submit" id="Add_Administrator" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"></div>
        </form>
    </div>

    <!--修改管理员-->
    <div id="update_administrator_style" class="add_menber" style="display:none">
        <form th:action="@{/updateAdminReal}" method="post" id="form-admin-update">
            <input type="hidden" name="id" value="">
            <div class="form-group">
                <label class="form-label"><span class="c-red">*</span> 管理员登录名：</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" placeholder="" id="user-name-update" name="loginName" datatype="*2-16" nullmsg="登录名不能为空">
                    <label class="error"></label>
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label"><span class="c-red">*</span>管理员真实名：</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" placeholder="" id="user-name1-update" name="name" datatype="*2-16" nullmsg="真实名不能为空">
                    <label class="error"></label>
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label"><span class="c-red">*</span>初始密码：</label>
                <label class="error"></label>
                <div class="formControls">
                    <input type="password" placeholder="密码" id="pwd1" name="password" autocomplete="off" value="" class="input-text" datatype="*6-20" nullmsg="密码不能为空">
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label "><span class="c-red">*</span>确认密码：</label>
                <div class="formControls ">
                    <input type="password" placeholder="确认新密码" id="pwd2" autocomplete="off" class="input-text Validform_error" errormsg="您两次输入的新密码不一致！" datatype="*" nullmsg="请再输入一次新密码！" recheck="userpassword" name="pwd">
                    <label class="error"></label>
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label "><span class="c-red">*</span>性别：</label>
                <div class="formControls  skin-minimal">
                    <label><input name="gender" id="man" type="radio" value="男" class="ace"><span class="lbl">男</span></label>&nbsp;&nbsp;
                    <label><input name="gender" id="woman" type="radio" value="女" class="ace"><span class="lbl">女</span></label>
                </div>
                <label class="error"></label>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label "><span class="c-red">*</span>手机：</label>
                <div class="formControls ">
                    <input type="text" class="input-text" value="" placeholder="" id="user-tel-update" name="phone" datatype="m" nullmsg="手机号不能为空">
                    <label class="error"></label>
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>

            <div class="form-group">
                <label class="form-label">角色：</label>
                <div class="formControls "> <span class="select-box" style="width:150px;">
				<select class="select" name="role.rid" size="1">
					<option value="0">超级管理员</option>
					<option value="1">管理员</option>
					<option value="2">栏目主辑</option>
					<option value="3">栏目编辑</option>
				</select>
                    <label class="error"></label>
				</span> </div>
            </div>

            <div>
                <input class="btn btn-primary radius" type="submit" id="Add_Administrator_update" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"></div>
        </form>
    </div>
</div>
</body>

<script type="text/javascript" th:inline="none">
    $(function () {
        $('#form-admin-update').validate({
            rules:{
                loginName:{required: true,rangelength:[2,10]},
                name:{required: true,rangelength:[2,10]},
                password:{required: true,minlength:6,maxlength:15},
                pwd:{required: true,minlength:6,maxlength:15,equalTo:'#pwd1'},
                phone:{required: true,minlength:11,maxlength:11},
            },
            messages:{
                name:{
                    required:"角色名不能为空",
                    rangelength: "长度在2-10之间",
                },
                loginName:{
                    required:"角色名不能为空",
                    rangelength: "长度在2-10之间",
                },
                password: {
                    required:"描述不能为空",
                    minlength:"密码最少为6位",
                    maxlength:"密码最长为15位",
                },
                pwd:{
                    required:"描述不能为空",
                    minlength:"密码最少为6位",
                    maxlength:"密码最长为15位",
                    equalTo: "两次密码输入不一致",
                },
                phone:{
                    required:"手机号不能为空",
                    minlength:"手机号长度为11位",
                    maxlength:"手机号长度为11位",
                }
            }
        })
    })

    $(function () {
        $('#form-admin-add').validate({
            rules:{
                loginName:{required: true,rangelength:[2,10]},
                name:{required: true,rangelength:[2,10]},
                password:{required: true,minlength:6,maxlength:15},
                pwd:{required: true,minlength:6,maxlength:15,equalTo:'#pwd1'},
                phone:{required: true,minlength:11,maxlength:11},
            },
            messages:{
                name:{
                    required:"角色名不能为空",
                    rangelength: "长度在2-10之间",
                },
                loginName:{
                    required:"角色名不能为空",
                    rangelength: "长度在2-10之间",
                },
                password: {
                    required:"描述不能为空",
                    minlength:"密码最少为6位",
                    maxlength:"密码最长为15位",
                },
                pwd:{
                    required:"描述不能为空",
                    minlength:"密码最少为6位",
                    maxlength:"密码最长为15位",
                    equalTo: "两次密码输入不一致",
                },
                phone:{
                    required:"手机号不能为空",
                    minlength:"手机号长度为11位",
                    maxlength:"手机号长度为11位",
                }
            }
        })
    })

    jQuery(function($) {
        var oTable1 = $('#sample_table').dataTable( {
            "aaSorting": [[ 1, "desc" ]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable":false,"aTargets":[0,2,3,4,5]}// 制定列不参与排序
            ] } );


        $('table th input:checkbox').on('click' , function(){
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function(){
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });


        $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
        function tooltip_placement(context, source) {
            var $source = $(source);
            var $parent = $source.closest('table')
            var off1 = $parent.offset();
            var w1 = $parent.width();

            var off2 = $source.offset();
            var w2 = $source.width();

            if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
            return 'left';
        }
    });

</script>
<script type="text/javascript">
    $(function() {
        $("#administrator").fix({
            float : 'left',
            //minStatue : true,
            skin : 'green',
            durationTime :false,
            spacingw:50,//设置隐藏时的距离
            spacingh:270,//设置显示时间距
        });
    });
    //字数限制
    function checkLength(which) {
        var maxChars = 100; //
        if(which.value.length > maxChars){
            layer.open({
                icon:2,
                title:'提示框',
                content:'您输入的字数超过限制!',
            });
            // 超过限制的字数了就将 文本框中的内容按规定的字数 截取
            which.value = which.value.substring(0,maxChars);
            return false;
        }else{
            var curr = maxChars - which.value.length; //250 减去 当前输入的
            document.getElementById("sy").innerHTML = curr.toString();
            return true;
        }
    };
    //初始化宽度、高度
    $(".widget-box").height($(window).height()-70);
    $(".table_menu_list").width($(window).width()-260);
    $(".table_menu_list").height($(window).height()-70);
    //当文档窗口发生改变时 触发
    $(window).resize(function(){
        $(".widget-box").height($(window).height()-215);
        $(".table_menu_list").width($(window).width()-260);
        $(".table_menu_list").height($(window).height()-215);
    })
    laydate({
        elem: '#start',
        event: 'focus'
    });

    /*用户-停用*/
    function member_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){
            $.ajax({
                url:'/adminStop',
                type:'get',
                dataType:'json',
                data:'id='+id,
                success:function(data){
                    if (data == 1){
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs " onClick="member_start(this,'+id+')" href="javascript:;" title="启用"><i class="fa fa-close bigger-120"></i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
                    $(obj).remove();
                    layer.msg('已停用!',{icon: 5,time:1000});
                    }
                }
            })
        });
    }
    /*用户-启用*/
    function member_start(obj,id){
        layer.confirm('确认要启用吗？',function(index){
            $.ajax({
                url:'/adminStart',
                type:'get',
                dataType:'json',
                data:'id='+id,
                success:function(data){
                    if (data == 1){
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onClick="member_stop(this,'+id+')" href="javascript:;" title="停用"><i class="fa fa-check  bigger-120"></i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
                    $(obj).remove();
                    layer.msg('已启用!',{icon: 6,time:1000});
                    }
                }
            })
        });
    }
    /*产品-编辑*/
    function member_edit(title,url,id,w,h){
        layer_show(title,url,w,h);
    }

    /*产品-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                url:'/del',
                type:'get',
                dataType:'json',
                data:'id='+id,
                success:function (data) {
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                }
            })
        });
    }

    /*修改管理员*/
    function administrator_update(id){
        $.ajax({
            url:'/updateAdmin',
            type:'get',
            dataType:'json',
            data:'id='+id,
            success:function (data) {
                $('input[type=hidden]').val(data.id);
                $('#user-name-update').val(data.loginName);
                $('#pwd1').val(data.pwd);
                $('#pwd2').val(data.pwd);
                $('#user-name1-update').val(data.name);
                if (data.gender=='男'){
                    $('#man').attr('checked',true);
                }else{
                    $('#woman').attr('checked',true);
                }
                $('#user-tel-update').val(data.phone);
                $('option[value="'+data.role.rid+'"]').attr("selected",true);
                layer.open({
                    type: 1,
                    title:'修改管理员',
                    area: ['700px',''],
                    shadeClose: false,
                    content: $('#update_administrator_style'),
                });
            }
        })
    }

    /*添加管理员*/
    function administrator_add(){
        layer.open({
            type: 1,
            title:'添加管理员',
            area: ['700px',''],
            shadeClose: false,
            content: $('#add_administrator_style'),
        });
    }

    /*$('#administrator_add').click(function(){
        alert(123);
        layer.open({
            type: 1,
            title:'添加管理员',
            area: ['700px',''],
            shadeClose: false,
            content: $('#add_administrator_style'),

        });
    })*/
    //表单验证提交
    $("#form-admin-add").Validform({

        tiptype:2,

        callback:function(data){
            //form[0].submit();
            if(data.status==1){
                layer.msg(data.info, {icon: data.status,time: 1000}, function(){
                    location.reload();//刷新页面
                });
            }
            else{
                layer.msg(data.info, {icon: data.status,time: 3000});
            }
            var index =parent.$("#iframe").attr("src");
            parent.layer.close(index);
            //
        }


    });
</script>
</html>

